#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cctype>

using std::vector;
using std::list;
using std::string;
using std::ostream;
using std::ifstream;
using std::ofstream;
using std::istringstream;
using std::cout; 
using std::endl;
using std::set;
using std::map;
using std::string;



// 使用map重写词频统计作业。（之前使用的vector，可以比较他们的速率）



class Dictionary
{
public:
    void Read(ifstream& ifs);
    void outPut(ofstream& ofs);
    bool legalWord(string& word);
private:
    map<string, size_t> _words;
};

void Dictionary::Read(ifstream& ifs){
    string word;

    
    while(ifs >> word){
        if(legalWord(word))
            _words[word]++;
    }
}

bool Dictionary::legalWord(string& word){
    for(auto& elem : word){
        if(!isalpha(elem)){return false;}
    }
    return true;
}
void Dictionary::outPut(ofstream& ofs){
    for(auto& elem : _words){
        ofs << elem.first << "\t";
        ofs << elem.second <<endl;
    }
}

int main()
{
    ifstream ifs("The_Holy_Bible.txt");
    Dictionary D;
    D.Read(ifs);
    ofstream ofs("out.txt");
    D.outPut(ofs);
}